<template>
  <div>
     <template v-for="item in this.menuList">
       <!--任务管理-->
      <el-submenu :disabled="item.disabled" :index="item.id+''" :key="item.id+''" v-if = "item.children.length>0">
        <template slot="title">
          <i :class="item.icon"></i>
          <span slot="title">{{ item.menuName }}</span>
        </template>
        <MenuTree :menuList="item.children"></MenuTree>
      </el-submenu>
       <!--子菜单-->
       <!--        -->
      <el-menu-item
        v-else
        :disabled="item.disabled"
        :index = "item.url + ''"
        :route = "item.url + ''"
        :key = "item.id"
        :style="{'color':clickId==item.id?'#1DA394':'#777777','font-weight':clickId==item.id?'bold':'normal'}"
        @click="savePath(item.url,item.id)"
      >
          <i :class = "item.icon" ></i>
        <span slot = "title">{{item.menuName}}</span>
      </el-menu-item>
    </template>
  </div>
</template>

<script>
export default {
  name: 'MenuTree',
  /* 接收传递过来的参数 */
  props: ['menuList'],
  created () {
    this.active = this.$route.name
    for(let menu of this.menuList){
      if(menu.url == this.$route.name){
        this.clickId = menu.id
        break
      }
    }
  },
  data () {
    return {
      active: '',
      clickId: -1,
    }
  },
  methods: {
    // 保存激活路径
    savePath (path, id) {
      this.clickId = id
      console.log("index",id)
      window.sessionStorage.setItem('activePath', path)
      // 调用Main.vue的activePath
      this.activePath = path
      console.log(this.activePath)
    }
  }
}

</script>
<style lang = "less" scoped>
/*实现了一个溢出处理*/
  .el-menu--collapse span,
  .el-menu--collapse i.el-submenu__icon-arrow {
    height: 0;
    width: 0;
    overflow: hidden;
    visibility: hidden;
    display: inline-block;
  }
</style>
